<%@ page import="java.util.ArrayList" %>
<%@ page import="service.FavouriteService" %>
<%@ page import="service.impl.FavouriteServiceImpl" %>
<%@ page import="service.LikesService" %>
<%@ page import="pojo.*" %>
<%@ page import="service.impl.LikesServiceImpl" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<script src="script/jquery-3.3.1.js"></script>
<html>
<head>
    <title>Title</title>
    <script type="text/javascript">
        function searchNotes(){
            var content=$("#search_input").val();
            if(content==""||content==null){
                alert("搜索内容为空！");
            }else{
                location.href="${pageContext.request.contextPath}/pageServlet?action=afterSearchPage";
            }
        }

        document.getElementById("order").onclick=function() {
            var order=$("#order").val();
            if(order=="收藏量"){
                var content=${content};
                var favourite="favourite";
                location.href="${pageContext.request.contextPath}/pageServlet?action=afterSearchPageByFavourite"+"&favourite="+favourite;
            }
            if(order=="点赞量"){
                location.href="${pageContext.request.contextPath}/pageServlet?action=afterSearchPage"+"&labelSearch="+labelSearch;
            }
            if(order=="浏览量"){
                location.href="${pageContext.request.contextPath}/pageServlet?action=afterSearchPage"+"&labelSearch="+labelSearch;
            }
        }
    </script>
    <style>
        *{
            margin: 0px;
            padding: 0px;
            box-sizing: border-box;
        }
        .bag{
            width: 500px;
            height:110px;
            border: 8px solid #EEEEEE;
            margin: auto;
            padding: 15px;

        }
        .choice{
            border: 1px solid lightskyblue;
            margin: auto;
        }
        .button{
            /*border: 1px solid dodgerblue;*/
            /*background-color: dodgerblue;*/
            align-content: center;
            /*// margin-top: 200px;*/
        }
        #firstPage{
            margin-left: 790px;
            margin: auto;
        }
        #view{
            float: right;
            margin: auto;
        }
        #game{
            margin-left: 15px;
            margin-right: 20px;
        }
        #food{
            margin-left: 15px;
            margin-right: 20px;
        }
        #cartoon{
            margin-left: 15px;
            margin-right: 10px;
        }
        .end{
            float: right;
            margin-top: 10px;
        }
        .title_left{
            margin-left: 420px;
        }
        .type,.label{
            margin-left: 420px;
        }
        .content_left{
            border:1px solid black;
            width: 440px;
            margin-left: 420px;
            height: 100px;
            margin-bottom: 20px;
        }
        .page{
            margin-left: 420px;
        }
        .active{
            border:1px solid lightskyblue;
            background-color:lightskyblue;
            width:12px;
            height:10px;
        }
        .nonactive{
            border:1px solid black;
            width:12px;
            height:10px;
        }
    </style>
</head>
<body>
<h3 align="center">搜索结果</h3>
<%
    String usename= (String) session.getAttribute("usename");
    User userLogin= (User) session.getAttribute("userLogin");
    String content=request.getParameter("content");
    String labelSearch=request.getParameter("labelSearch");
%>
<a href="${pageContext.request.contextPath}/pageServlet?action=allNotesPage" class="button" type="submit" id="firstPage">返回首页</a>
<br>

<%--<div class="search" align="center">--%>
<%--    <input name="" type="text" id="search_input" placeholder="请输入标签" class="search_input">--%>
<%--    <a href="javascript:searchNotes();" id="search-button" class="search-button">搜索</a>--%>
<%--</div>--%>

<select id="order" name="label" datatype="*">
    <option>收藏量</option>
    <option>点赞量</option>
    <%--    <option>热度</option>--%>
    <option>浏览量</option>
</select>
<input type="button" value="降序" id="desc">
<input type="button" value="升序" id="asce">

<%
    request.getParameter("noteLabelArrays");
    request.getParameter("page");
    int i=0;
    request.setAttribute("order",i);
%>
<c:forEach items="${page.list}" var="note" varStatus="s">
    <form>
        <table>
            <tr>
                <td>
                    <h5 class="title_left">${order=order+1}.${note.title}</h5>
                    <h5 class="type">${note.type}</h5>

<span class="label">
    <c:forEach items="${noteLabelArrays}" var="labelArrays" varStatus="s">
        <c:if test="${labelArrays.nid==note.nid}">
            <c:forEach items="${labelArrays.labelList}" var="Label" varStatus="s">
                <ui>${Label.label}</ui>
            </c:forEach>
        </c:if>
    </c:forEach>
</span>



                    <a href="${pageContext.request.contextPath}/note.jsp?nid=${note.nid}&uid=${userLogin.uid}"><p class="content_left">${note.content}</p></a>
            </tr>
        </table>
    </form>
</c:forEach>
<div class="page">
    <nav aria-label="page navigation">
        <ul class="pagination">
<c:if test="${page.currentPage==1}">
    <span aria-label="Previous">
        <span aria-hidden="true">&laquo;</span>
    </span>
</c:if>
<c:if test="${page.currentPage!=1}">
            <a href="${pageContext.request.contextPath}/pageServlet?action=afterSearchPage&currentPage=${page.currentPage-1}&rows=5&content=${content}&labelSearch=${labelSearch}" aria-label="Previous">
                <span aria-hidden="true">&laquo;</span>
            </a>
</c:if>
<c:forEach begin="1" end="${page.totalPage}" var="i">

    <c:if test="${page.currentPage==i}">
        <a href="${pageContext.request.contextPath}/pageServlet?action=afterSearchPage&currentPage=${i}&rows=5&content=${content}&labelSearch=${labelSearch}"  class="active">${i}</a>
    </c:if>
    <c:if test="${page.currentPage!=i}">
        <a href="${pageContext.request.contextPath}/pageServlet?action=afterSearchPage&currentPage=${i}&rows=5&content=${content}&labelSearch=${labelSearch}" class="nonactive">${i}</a>
    </c:if>
</c:forEach>
       <c:if test="${page.currentPage!=page.totalPage}">
           <a href="${pageContext.request.contextPath}/pageServlet?action=afterSearchPage&currentPage=${page.currentPage+1}&rows=5&content=${content}&labelSearch=${labelSearch}" aria-label="Next">
               <span aria-hidden="true">&raquo;</span>
           </a>
       </c:if>
            <c:if test="${page.currentPage==page.totalPage}">
                <span aria-label="Next">
                    <span aria-hidden="true">&raquo;</span>
                </span>
            </c:if>
            <span style="font-size: 20px;margin-left: 5px;">
                共${page.total}条笔记，共${page.totalPage}页
            </span>
        </ul>
    </nav>
</div>
</body>
</html>
